
/*
 *
 *  Copyright (C) 2012-2024
 *  All rights reserved, Designed By 杭州连线客信息技术有限公司
 *  注意：
 *  本软件为杭州连线客信息技术有限公司开发研制，未经购买不得使用
 *  购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 *  一经发现盗用、分享等行为，将追究法律责任，后果自负
 *
 */

package org.dromara.setting.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.setting.domain.bo.SettingConfigGroupBo;
import org.dromara.setting.domain.vo.SettingConfigGroupVo;
import org.dromara.setting.service.ISettingConfigGroupService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 渠道配置-配置组-后台管理
 *
 * @author LXK-RY5
 * @date 2024-08-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/setting/configGroup")
@Slf4j
public class SettingConfigGroupController extends BaseController {

    private final ISettingConfigGroupService settingConfigGroupService;

    /**
     * 查询配置组列表
     */
    @SaCheckPermission("setting:configGroup:list")
    @GetMapping("/list")
    public TableDataInfo<SettingConfigGroupVo> list(SettingConfigGroupBo bo, PageQuery pageQuery) {
        return settingConfigGroupService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出配置组列表
     */
    @SaCheckPermission("setting:configGroup:export")
    @Log(title = "配置组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SettingConfigGroupBo bo, HttpServletResponse response) {
        List<SettingConfigGroupVo> list = settingConfigGroupService.queryList(bo);
        ExcelUtil.exportExcel(list, "配置组", SettingConfigGroupVo.class, response);
    }

    /**
     * 获取配置组详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("setting:configGroup:query")
    @GetMapping("/{id}")
    public R<SettingConfigGroupVo> getInfo(@NotNull(message = "主键不能为空")
                                           @PathVariable Long id) {
        return R.ok(settingConfigGroupService.queryById(id));
    }

    /**
     * 新增配置组
     */
    @SaCheckPermission("setting:configGroup:add")
    @Log(title = "配置组", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SettingConfigGroupBo bo) {
        return toAjax(settingConfigGroupService.insertByBo(bo));
    }

    /**
     * 修改配置组
     */
    @SaCheckPermission("setting:configGroup:edit")
    @Log(title = "配置组", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SettingConfigGroupBo bo) {
        return toAjax(settingConfigGroupService.updateByBo(bo));
    }

    /**
     * 删除配置组
     *
     * @param ids 主键串
     */
    @SaCheckPermission("setting:configGroup:remove")
    @Log(title = "配置组", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(settingConfigGroupService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 查询支付配置组
     */
    @SaCheckPermission("setting:configGroup:apylist")
    @GetMapping("/pay/list")
    public R<List<SettingConfigGroupVo>> list() {
        return R.ok(settingConfigGroupService.queryPayList());
    }
}
